<template>
	<view>
		<view style="display: flex; margin: 30rpx;justify-content: center;align-items: center;">
			<image style="width: 300rpx;height: 300rpx;" mode="aspectFit" src="../../../static/icon_payee.png"></image>
		</view>
		<view style="font-size: 36rpx;text-align: center;">开通成为委托收款人</view>
		<view class="view-button" @click="onnext()">申请开通</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			shipInfo: {}
		};
	},
	onShow() {
		if (uni.getStorageSync('payAuthFlag')) {
			this.wxRequest({
				url: `${this.API}/captainApp/captainAuthentication?etpId=${uni.getStorageSync(this.DATA_KEY.etpId)}`,
				method: 'GET',
				title: '加载中...',
				success: res => {
					console.log(res)
					if (res.data.code == 0) {
						this.shipInfo = res.data.data
						console.log(this.shipInfo)
						if (this.shipInfo.captainStatus == '1' && this.shipInfo.platformDriverLiveStatus == '1') {
							let that = this
							that.wxRequest({
								url: `${that.API}/captainApp/applicationPayee?etpId=${res.data.data.captain.etpId}`,
								method: 'GET',
								title: '加载中...',
								success: applyRes => {
									if (applyRes.data.code == 0) {
										uni.showToast({
											title: '申请成功',
											success() {
												setTimeout(()=>{
													uni.redirectTo({
														url: '/pages/ship/user/billingmessage'
													})
												}, 800)
											}
										})
									} else {
										uni.showToast({
											title: applyRes.data.msg,
											icon: 'none'
										})
									}
								}
							})
						} else {
							uni.showToast({
								title: '用户未认证',
								icon: 'none'
							})
						}
					}
				}
			})
			uni.removeStorageSync('payAuthFlag')
		}
	},
	methods: {
		
		onnext() {
			let that = this
			this.wxRequest({
				url: `${this.API}/captainApp/captainAuthentication?etpId=${uni.getStorageSync(this.DATA_KEY.etpId)}`,
				method: 'GET',
				title: '加载中...',
				success: res => {
					console.log(res)
					if (res.data.code == 0) {
						this.shipInfo = res.data.data
						console.log(this.shipInfo)
						if (this.shipInfo.captainStatus === '0' && this.shipInfo.platformDriverLiveStatus === '0') {
							// 未实名未活体
							uni.navigateTo({
								url: '/pages/ship/user/infoSet?pay=1'
							})
							uni.setStorageSync('payAuthFlag', true)
						} else if (this.shipInfo.captainStatus === '1' && this.shipInfo.platformDriverLiveStatus === '0') {
							uni.navigateTo({
								url: '/pages/ship/user/delegatedPavee'
							})
							uni.setStorageSync('payAuthFlag', true)
						} else {
							that.wxRequest({
								url: `${that.API}/captainApp/applicationPayee?etpId=${uni.getStorageSync(this.DATA_KEY.etpId)}`,
								method: 'GET',
								title: '加载中...',
								success: applyRes => {
									if (applyRes.data.code == 0) {
										uni.showToast({
											title: '申请成功',
											success() {
												setTimeout(()=>{
													uni.redirectTo({
														url: '/pages/ship/user/billingmessage'
													})
												}, 800)
											}
										})
									} else {
										uni.showToast({
											title: applyRes.data.msg,
											icon: 'none'
										})
									}
								}
							})
							
						}
					}
				}
			});
			
		},
		getShipInfo() {
			this.wxRequest({
				url: `${this.API}/captainApp/captainAuthentication?etpId=${uni.getStorageSync(this.DATA_KEY.etpId)}`,
				method: 'GET',
				success: res => {
					if (res.data.code == 0) {
						this.shipInfo = res.data.data
					}
				}
			});
		}
	},
};
</script>

<style>
.row-css {
	display: flex;
	flex-direction: row;
}

.column-css {
	display: flex;
	flex-direction: column;
}
.view-button {
	display: flex;
	flex: 1;
	background: #2b7cff;
	border-radius: 5rpx;
	padding: 20rpx;
	margin: 30rpx;
	margin-top: 50rpx;
	justify-content: center;
	color: #ffffff;
}
</style>
